/* OPTIONS OBS=5000  NOREPLACE ;  */


/* Export cmf (with imputed data replaced with missing values) files to .csv format. */

%include "ASMimplibs.sas";



%macro export(year=);

 /* Keep the variables we need for the CART imputes 
   and save the IDs for re-merging after CART imputes. */

 data cmf_all_inds&year;
  set allcmf.gooddata_all_inds&year;
   dinv = tie - tib;
   cenergy = sum(cf,ee);
   if cm>0 then energycmratio = cenergy/cm;
   if sw>0 then wwswratio = ww/sw;
 run;

 proc sort data=cmf_all_inds&year; by NAICS_NEW_6; run;

 data gooddata_all_inds&year (keep = NAICS_NEW_6 tvs dinv cm energycmratio sw te ph wwswratio tae)
      allcmf.gooddata_ids_all_inds&year (keep = number survu_id firmid );
  set cmf_all_inds&year;
   number = _N_; 
 run;

 PROC EXPORT DATA= gooddata_all_inds&year 
  OUTFILE= "gooddata_all_inds&year..csv" DBMS=CSV REPLACE;
      PUTNAMES=YES;
 RUN;

%mend;


%export(year=02);
%export(year=07);

